;+
; NAME:
;       MIE_DIST
; PURPOSE:
;       Calculates scattering properties of a given distribution of particles.
; INPUTS:
;       N_R: vector of number distribution, UNIT: cm-3 * micron-1
;       R: vector of particle radius, UNIT: micron
;       LAMBDA: wavelength, UNIT: micron
;       Cm: Complex Reflect index
;       DQV: vector cos of scattering angles
; OUTPUTS:
;       KXT: extinction, UNIT: 1/(10^6 m)
;       KSC: scattering, UNIT: 1/(19^6 m)
;-

pro mie_dist,N_r,r,lambda,Cm,Dqv=dqv,Kxt,Ksc,Kbk,Dph,log=log

  ; define consts
  Dx = 2 * !dpi * r / lambda
  if KEYWORD_SET(LOG) then begin
    ; do nothing
    print,'log distribution part has not come yet.'
  endif else begin ; not log distribution
    size_r = n_elements(r)
    dr = r[1:size_r-1]-r[0:size_r-2]
    Mie_single,Dx,Cm,Dqxt,Dqsc,Dqbk,Dg,Xs1,Xs2,Dph,dqv=dqv
    factor = !dpi * (r[1:size_r-1])^2  * N_r[1:size_r-1] * dr
    Kxt = total(factor * Dqxt[1:size_r-1])
    Ksc = total(factor * Dqsc[1:size_r-1])
    Kbk = total(factor * Dqbk[1:size_r-1])
;    if KEYWORD_SET(Dqv) then begin
    if (N_params() gt 7) then begin
      Inp = n_elements(dqv)
      eta = dblarr(Inp)
      for i = 0, Inp - 1 do begin
        eta[i] = total(factor * Dph[i,1:size_r-1] * Dqsc [1:size_r-1]) / Ksc
      endfor
    endif
  endelse
end
